{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Scipy库 常用操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.  0.  0.  0.  0.]\n",
      " [ 0.  0.  0.  0.  0.]\n",
      " [ 0.  0.  0.  1.  0.]\n",
      " [ 0.  3.  0.  0.  2.]\n",
      " [ 0.  0.  0.  0. 10.]\n",
      " [ 0.  0.  0.  0.  0.]]\n"
     ]
    }
   ],
   "source": [
    "import pdb\n",
    "import jieba\n",
    "import torch\n",
    "import numpy as np\n",
    "from scipy import sparse\n",
    "\n",
    "l = sparse.lil_matrix((6,5))\n",
    "l[2,3] += 1\n",
    "l[3,4] += 2\n",
    "l[3,1] += 3\n",
    "l[4,4] += 10\n",
    "print(l.toarray())\n",
    "ls = l.sum(1)\n",
    "for ind,k in enumerate(l.data):\n",
    "    if len(k):\n",
    "        l.data[ind] = [i/ls[ind,0] for i in k]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
